package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.dto.customer.CustomerDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @GetMapping
    public Result listCustomers(CustomerDTO dto){
        return Result.success(customerService.listCustomers(dto));
    }

    @GetMapping("/{id}")
    public Result getCustomerById(@PathVariable Long id){
        return Result.success(customerService.getCustomerById(id));
    }

    @PostMapping
    public Result addCustomer(@RequestBody Customer customer){
        customerService.addCustomer(customer);
        return Result.success();
    }

    @PutMapping
    public Result updateCustomer(@RequestBody Customer customer){
        customerService.updateCustomerById(customer);
        return Result.success();
    }
}
